package ckw.gui.wizards;

import java.util.ArrayList;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.List;

import ckw.database.OKW;

/**
 * @author DoomThrower
 *
 */
public class WzdConfigurationPg1 extends WizardPage {
	
	private Composite container;
	private List multi;


	public WzdConfigurationPg1() {
		super("Krok 1.");
		setTitle("Krok 1.");
		setDescription("Prosze wybrac Okregowe Komisje Wyborcze, dla ktorych maja zostac ustawione konfiguracje.");
	}

	public void createControl(Composite parent) {
		container = new Composite(parent, SWT.NULL);
		FillLayout layout = new FillLayout();
		container.setLayout(layout);

		ArrayList<OKW> okwList = ((WzdConfiguration)getWizard()).getOkwList();
		multi = new List(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
		String[] items = new String[okwList.size()];
		for (int i = 0; i < okwList.size(); i++) {
			items[i] = okwList.get(i).getName();
		}
		multi.setItems(items);
		multi.addSelectionListener(new SelectionListener() {

			public void widgetSelected(SelectionEvent arg0) {
				getWizard().getContainer().updateButtons();
			}

			public void widgetDefaultSelected(SelectionEvent arg0) {
				// TODO Auto-generated method stub

			}
		});
		// Required to avoid an error in the system
		setControl(container);
	}

	public int[] getSelectedIds() {
		return multi.getSelectionIndices();
	}

	public boolean canFlipToNextPage() {
		if (multi.getSelection().length != 0) {
			return true;
		} else {
			return false;
		}
	}

	// Przeciazenie, zeby przekazac liste wybranych OKW do storny drugiej i tam wygenerowac odpowiednie kontrolki
	public IWizardPage getNextPage() {
		WzdConfigurationPg2 pageTwo = ((WzdConfiguration) getWizard()).two;
		pageTwo.onEnterPage(multi.getSelectionIndices());
		return pageTwo;
	}
}